﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MessageRouter.Configuration
{
    sealed class RouterModelConfigurationSection : ConfigurationSection
    {
        const string readersPropertyName = "readers";
        const string writersPropertyName = "writers";
        const string bindingsPropertyName = "bindings";

        private static readonly ConfigurationProperty readersProperty = new ConfigurationProperty(readersPropertyName, typeof(ReaderConfigurationElementCollection));
        private static readonly ConfigurationProperty writersProperty = new ConfigurationProperty(writersPropertyName, typeof(WriterConfigurationElementCollection));
        private static readonly ConfigurationProperty bindingsProperty = new ConfigurationProperty(bindingsPropertyName, typeof(BindingConfigurationElementCollection));

        private static readonly ConfigurationPropertyCollection properties;

        [ConfigurationProperty(readersPropertyName)]
        internal ReaderConfigurationElementCollection Readers
        {
            get { return (ReaderConfigurationElementCollection)base[readersProperty]; }
        }

        [ConfigurationProperty(writersPropertyName)]
        internal WriterConfigurationElementCollection Writers
        {
            get { return (WriterConfigurationElementCollection)base[writersProperty]; }
        }

        [ConfigurationProperty(bindingsPropertyName)]
        internal BindingConfigurationElementCollection Bindings
        {
            get { return (BindingConfigurationElementCollection)base[bindingsProperty]; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return properties; }
        }

        internal RouterModelConfigurationSection() { }

        static RouterModelConfigurationSection()
        {
            properties = new ConfigurationPropertyCollection
            {
                readersProperty,
                writersProperty,
                bindingsProperty,
            };
        }
    }
}
